extends NodeState


@export var igorBoss: IgorBoss

var direction: Vector2


func _on_process(_delta : float) -> void:
	igorBoss.flip_sprite()
	move_to_player()



func _on_enter() -> void:
	direction = Vector2.ZERO
	process_animation()


func _on_exit() -> void:
	pass



func move_to_player():
	if _changing_state:
		return
	# 接近到一定距离后转换状态
	if igorBoss.global_position.distance_squared_to(igorBoss.player.global_position) < igorBoss.attack_distance:
		# 应该转换到攻击状态
		transition_state(igorBoss.next_attack_state())
		return
	elif igorBoss.is_player_within_sprint_range():
		transition_state(IgorBoss.STATE_SPRINT)
		return
	direction = (igorBoss.player.global_position - igorBoss.global_position).normalized()
	igorBoss.velocity = direction * igorBoss.speed
	igorBoss.move_and_slide()



func process_animation():
	igorBoss.animationPlayer.play(IgorBoss.ANIMATION_WALK)
